package com.example.demo.Repository;


import com.example.demo.Entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Optional;

@Repository
public interface UserRepo extends JpaRepository<User, Long> {
    public Optional<User> findByUsername(String userName);
    public User  findByEmail(String Email);
    public User findByPhoneNumber(String PhoneNumber);
    public List<User>  findByRole(String Role);
    public List<User>  findByRegistrationDate(Date RegistrationDate);
    public User findById(long id);

    @Transactional
    @Modifying
    @Query("UPDATE User u SET u.status = :status WHERE u.username = :username")
    int updateUserStatusByUsername(String username, int status);

}
